package ru.papergames.web.blines.battle.network.serverpackets;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import ru.papergames.common.beans.BattleMember;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: ATroshanin
 * Date: 17.06.2010
 * Time: 15:45:18
 */
public class BattleFinishNotification extends WebServerServerPacket {

    private static Log log = LogFactory.getLog(BattleFinishNotification.class);

    private int battleOrderId;
    private boolean winnerFound;
    private int winnerId;

    @Override
    protected void readImpl() {
        battleOrderId = readD();
        winnerFound = readC() == 1;
        winnerId = readC();
    }

    @Override
    protected void runImpl() {
        log.debug("BattleFinishNotification.runImpl");
        getClient().getConnectionHolder().onBattleFinish(battleOrderId, winnerFound ? winnerId : -1, new ArrayList<BattleMember>());
    }

    @Override
    public String getType() {
        return "[s] BattleFinishNotification [" + BATTLE_FINISH_NOTIFICATION_PACKET_ID + "]";
    }

}
